/*
 * Copyright 2003-2005 (c) Live Media Pty Ltd. <argot@einet.com.au> 
 *
 * This software is licensed under the Argot Public License 
 * which may be found in the file LICENSE distributed 
 * with this software.
 *
 * More information about this license can be found at
 * http://www.einet.com.au/License
 * 
 * The Developer of this software is Live Media Pty Ltd,
 * PO Box 4591, Melbourne 3001, Australia.  The license is subject 
 * to the law of Victoria, Australia, and subject to exclusive 
 * jurisdiction of the Victorian courts.
 */

#include "../Types.h"

#include "../common/BigEndianUnsignedShort.h"
#include "../meta/MetaName.h"

#include "Dictionary.h"

int type_map_write( type_output_stream * out, void * o, type_element * element, void * data )
{
	type_map * map = (type_map *) o;
	type_map_iterator iter;
	int rc;
	
	/* write the length out first. */
	int size = type_map_get_size( map );
	type_output_write_named_object( out, &uint16_name, &size );
	
	type_map_iterator_init( &iter, map );		
	while ( type_map_iterator_next( &iter ) )
	{
		int id = type_map_iterator_id( &iter );
		
		type_name * name = type_map_get_name( map, id );
		type_element * definition = type_map_get_structure( map, id );
	
		rc = type_output_write_named_object( out, &uint16_name, &id );
		if ( rc != TYPE_OK ) return NULL;
		rc = type_output_write_named_object( out, &meta_name_name, name );
		if ( rc != TYPE_OK ) return NULL;		
		rc = type_output_write_named_object( out, &dictionary_definition_name, definition );
		if ( rc != TYPE_OK ) return NULL;
	}
	
	return TYPE_OK;
}
